package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.ShopClientService;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.ReservedVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;
import com.junzhiit.nengji.cms.web.vo.ShopClientVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/client")
public class ShopClientController extends BaseController {
	
	@Autowired
	private ShopClientService shopClientService;
	
	@ApiOperation("查找该商户的所有客户")
	@RequestMapping(method = RequestMethod.GET)
	public Map<String, Object> findAll(DataTablesParamVO dtp,ShopClientVO shopClientVO) {
		return shopClientService.findAll(dtp, shopClientVO);
	}

	@ApiOperation("将客户升级为会员")
	@RequestMapping(value = "/add",method = RequestMethod.PUT)
	public ResultVO add(ShopClientVO shopClientVO) {
		return shopClientService.add(shopClientVO);
	}
	
	@ApiOperation("修改客户信息")
	@RequestMapping(value = "/update",method = RequestMethod.PUT)
	public ResultVO changeClient(ShopClientVO shopClientVO) {
		return shopClientService.changeClient(shopClientVO);
	}
	
	@ApiOperation("在线储值")
	@RequestMapping(value = "/charge",method = RequestMethod.PUT)
	public ResultVO memberCharge(ShopClientVO shopClientVO) {
		return shopClientService.memberCharge(shopClientVO);
	}
	
	@ApiOperation("根据ID查找该客户信息")
	@RequestMapping(value = "/find",method = RequestMethod.GET)
	public ResultVO findClientById(String clientId) {
		return shopClientService.findClientById(clientId);
	}
	
	@ApiOperation("商家预留会员编号")
	@RequestMapping(value = "/reserved",method = RequestMethod.PUT)
	public ResultVO setReserved(String sessionId,ReservedVO reservedVO) {
		return shopClientService.setReserved(sessionId,reservedVO);
	}
	
	@ApiOperation("查找该商户会员编号的最大值及预留范围值")
	@RequestMapping(value = "/value",method = RequestMethod.GET)
	public ResultVO findValue(String sessionId) {
		return shopClientService.findValue(sessionId);
	}
	
	@ApiOperation("商家赠送优惠券")
	@RequestMapping(value = "/give",method = RequestMethod.POST)
	public ResultVO giveCoupons(String userId,String couponsId) {
		AssertUtil.notNull(userId, "userId is required");
		AssertUtil.notNull(couponsId, "couponsId is required");
		return shopClientService.giveCoupons(userId,couponsId);
	}
}
